package com.fcy.teamwork.business.projectlife

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentManager
import androidx.viewbinding.ViewBinding
import com.fcy.teamwork.App
import com.fcy.teamwork.R
import com.fcy.teamwork.base.BaseRVAdapter
import com.fcy.teamwork.bean.User
import com.fcy.teamwork.business.SelectFromGroupDiaFragment
import com.fcy.teamwork.business.self.SelfInfoAct
import com.fcy.teamwork.databinding.LayoutOwnerListItemBinding
import com.fcy.teamwork.pojo.Person
import com.fcy.teamwork.pojo.ProjectInfo

class OwnerListAdapter(private val projectInfo: ProjectInfo) :
    BaseRVAdapter<Person, LayoutOwnerListItemBinding>() {
    lateinit var manager: FragmentManager
    override fun createBinding(
        inflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): LayoutOwnerListItemBinding {
        return LayoutOwnerListItemBinding.inflate(inflater, parent, false)
    }

    override fun bindView(holder: VH, position: Int, data: Person) {
        (holder.binding as? LayoutOwnerListItemBinding)?.apply {
            tvNikeName.text = data.nikeName
            pvPortrait.setImageResource(R.drawable.por2)
            root.setOnClickListener {
                val intent = Intent(root.context, SelfInfoAct::class.java).apply {
                    putExtra("canSenMsg", data.personId != App.person.personId)
                    putExtra("userName", data.personId)
                }
                root.context.startActivity(intent)
            }
        }
    }

    override fun hasFooter(): Boolean = true
    override fun createFootBinding(
        inflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ViewBinding {
        return LayoutOwnerListItemBinding.inflate(inflater, parent, false)
    }


    override fun bindFooterView(holder: VH, position: Int) {
        (holder.binding as? LayoutOwnerListItemBinding)?.apply {
            tvNikeName.text = "邀请"
            pvPortrait.setImageResource(R.drawable.ic_baseline_add_24)
            root.setOnClickListener {
                val fragment = SelectFromGroupDiaFragment()
                fragment.arguments = Bundle().apply {
                    putString(
                        SelectFromGroupDiaFragment.arguments_groupId,
                        projectInfo.id.toString()
                    )
                    putBoolean(SelectFromGroupDiaFragment.arguments_isHideCheckBox, false)
                }
                fragment.show(manager, "")
            }
        }
    }

}